package com.order.food.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.order.food.domain.OrderFood;
import com.order.food.service.IOrderFoodService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 食物管理Controller
 * 
 * @author huhu
 * @date 2020-08-19
 */
@Controller
@RequestMapping("/order/food")
public class OrderFoodController extends BaseController
{
    private String prefix = "order/food";

    @Autowired
    private IOrderFoodService orderFoodService;

    @RequiresPermissions("order:food:view")
    @GetMapping()
    public String food()
    {
        return prefix + "/food";
    }

    /**
     * 查询食物管理列表
     */
    @RequiresPermissions("order:food:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderFood orderFood)
    {
        startPage();
        List<OrderFood> list = orderFoodService.selectOrderFoodList(orderFood);
        return getDataTable(list);
    }

    /**
     * 导出食物管理列表
     */
    @RequiresPermissions("order:food:export")
    @Log(title = "食物管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderFood orderFood)
    {
        List<OrderFood> list = orderFoodService.selectOrderFoodList(orderFood);
        ExcelUtil<OrderFood> util = new ExcelUtil<OrderFood>(OrderFood.class);
        return util.exportExcel(list, "food");
    }

    /**
     * 新增食物管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存食物管理
     */
    @RequiresPermissions("order:food:add")
    @Log(title = "食物管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderFood orderFood)
    {
        return toAjax(orderFoodService.insertOrderFood(orderFood));
    }

    /**
     * 修改食物管理
     */
    @GetMapping("/edit/{foodId}")
    public String edit(@PathVariable("foodId") Long foodId, ModelMap mmap)
    {
        OrderFood orderFood = orderFoodService.selectOrderFoodById(foodId);
        mmap.put("orderFood", orderFood);
        return prefix + "/edit";
    }

    /**
     * 修改保存食物管理
     */
    @RequiresPermissions("order:food:edit")
    @Log(title = "食物管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderFood orderFood)
    {
        return toAjax(orderFoodService.updateOrderFood(orderFood));
    }

    /**
     * 删除食物管理
     */
    @RequiresPermissions("order:food:remove")
    @Log(title = "食物管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderFoodService.deleteOrderFoodByIds(ids));
    }
}
